#include "centralwidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>

CentralWidget::CentralWidget(QWidget *parent) :
    QWidget(parent)
{
    label_sum = new QLabel("SUM = 0");
    value_a = new QSpinBox(this);
    value_b = new QSpinBox(this);
    set_bttn = new QPushButton("SET",this);

    value_a->setMaximum(1000);
    value_a->setMinimum(-1000);
    value_b->setMaximum(1000);
    value_b->setMinimum(-1000);

    m_summator = new Summator(this);

    QVBoxLayout * vl = new QVBoxLayout();
    vl->addWidget(label_sum);

    QHBoxLayout * hl_a = new QHBoxLayout();
    hl_a->addWidget(new QLabel("A:"));
    hl_a->addWidget(value_a);

    vl->addItem(hl_a);

    QHBoxLayout * hl_b = new QHBoxLayout();
    hl_b->addWidget(new QLabel("B:"));
    hl_b->addWidget(value_b);

    vl->addItem(hl_b);

    vl->addWidget(set_bttn);

    setLayout(vl);

    connect(set_bttn, SIGNAL(clicked()),
            this, SLOT(set_bttn_pressed())
            );
    connect(m_summator, SIGNAL(valueChanged()),
            this, SLOT(summator_valuesChanged())
            );
}

void CentralWidget::set_bttn_pressed()
{
    m_summator->setA(value_a->value());
    m_summator->setB(value_b->value());
}

void CentralWidget::summator_valuesChanged()
{
    label_sum->setText("SUM = " + QString::number(m_summator->sum()));
}
